<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Box2D: b2DynamicTree.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="icon.gif"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Box2D
   &#160;<span id="projectnumber">2.2.1</span>
   </div>
   <div id="projectbrief">A 2D Physics Engine for Games</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">b2DynamicTree.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">* Copyright (c) 2009 Erin Catto http://www.box2d.org</span>
<a name="l00003"></a>00003 <span class="comment">*</span>
<a name="l00004"></a>00004 <span class="comment">* This software is provided &#39;as-is&#39;, without any express or implied</span>
<a name="l00005"></a>00005 <span class="comment">* warranty.  In no event will the authors be held liable for any damages</span>
<a name="l00006"></a>00006 <span class="comment">* arising from the use of this software.</span>
<a name="l00007"></a>00007 <span class="comment">* Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00008"></a>00008 <span class="comment">* including commercial applications, and to alter it and redistribute it</span>
<a name="l00009"></a>00009 <span class="comment">* freely, subject to the following restrictions:</span>
<a name="l00010"></a>00010 <span class="comment">* 1. The origin of this software must not be misrepresented; you must not</span>
<a name="l00011"></a>00011 <span class="comment">* claim that you wrote the original software. If you use this software</span>
<a name="l00012"></a>00012 <span class="comment">* in a product, an acknowledgment in the product documentation would be</span>
<a name="l00013"></a>00013 <span class="comment">* appreciated but is not required.</span>
<a name="l00014"></a>00014 <span class="comment">* 2. Altered source versions must be plainly marked as such, and must not be</span>
<a name="l00015"></a>00015 <span class="comment">* misrepresented as being the original software.</span>
<a name="l00016"></a>00016 <span class="comment">* 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00017"></a>00017 <span class="comment">*/</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#ifndef B2_DYNAMIC_TREE_H</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define B2_DYNAMIC_TREE_H</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;<a class="code" href="b2_collision_8h.html">Box2D/Collision/b2Collision.h</a>&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;Box2D/Common/b2GrowableStack.h&gt;</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="preprocessor">#define b2_nullNode (-1)</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span>
<a name="l00028"></a><a class="code" href="structb2_tree_node.html">00028</a> <span class="keyword">struct </span><a class="code" href="structb2_tree_node.html" title="A node in the dynamic tree. The client does not interact with this directly.">b2TreeNode</a>
<a name="l00029"></a>00029 {
<a name="l00030"></a>00030         <span class="keywordtype">bool</span> IsLeaf()<span class="keyword"> const</span>
<a name="l00031"></a>00031 <span class="keyword">        </span>{
<a name="l00032"></a>00032                 <span class="keywordflow">return</span> child1 == b2_nullNode;
<a name="l00033"></a>00033         }
<a name="l00034"></a>00034 
<a name="l00036"></a><a class="code" href="structb2_tree_node.html#a798f1a594b33c713be45e76e79912239">00036</a>         <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a> <a class="code" href="structb2_tree_node.html#a798f1a594b33c713be45e76e79912239" title="Enlarged AABB.">aabb</a>;
<a name="l00037"></a>00037 
<a name="l00038"></a>00038         <span class="keywordtype">void</span>* userData;
<a name="l00039"></a>00039 
<a name="l00040"></a>00040         <span class="keyword">union</span>
<a name="l00041"></a>00041         {
<a name="l00042"></a>00042                 int32 parent;
<a name="l00043"></a>00043                 int32 next;
<a name="l00044"></a>00044         };
<a name="l00045"></a>00045 
<a name="l00046"></a>00046         int32 child1;
<a name="l00047"></a>00047         int32 child2;
<a name="l00048"></a>00048 
<a name="l00049"></a>00049         <span class="comment">// leaf = 0, free node = -1</span>
<a name="l00050"></a>00050         int32 height;
<a name="l00051"></a>00051 };
<a name="l00052"></a>00052 
<a name="l00061"></a><a class="code" href="classb2_dynamic_tree.html">00061</a> <span class="keyword">class </span><a class="code" href="classb2_dynamic_tree.html">b2DynamicTree</a>
<a name="l00062"></a>00062 {
<a name="l00063"></a>00063 <span class="keyword">public</span>:
<a name="l00065"></a>00065         <a class="code" href="classb2_dynamic_tree.html#a8af64cf6a1566fa4c5b5c9683bd937d9" title="Constructing the tree initializes the node pool.">b2DynamicTree</a>();
<a name="l00066"></a>00066 
<a name="l00068"></a>00068         <a class="code" href="classb2_dynamic_tree.html#a9060565fc63b4dd87d9560775c076786" title="Destroy the tree, freeing the node pool.">~b2DynamicTree</a>();
<a name="l00069"></a>00069 
<a name="l00071"></a>00071         int32 <a class="code" href="classb2_dynamic_tree.html#ae44676f12977dada46037da47fc7ffbf" title="Create a proxy. Provide a tight fitting AABB and a userData pointer.">CreateProxy</a>(<span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabb, <span class="keywordtype">void</span>* userData);
<a name="l00072"></a>00072 
<a name="l00074"></a>00074         <span class="keywordtype">void</span> <a class="code" href="classb2_dynamic_tree.html#a62aa451e7d7fe029818dd05f76ea9cdc" title="Destroy a proxy. This asserts if the id is invalid.">DestroyProxy</a>(int32 proxyId);
<a name="l00075"></a>00075 
<a name="l00080"></a>00080         <span class="keywordtype">bool</span> <a class="code" href="classb2_dynamic_tree.html#a7748252811f3c575015931399cbe4daa">MoveProxy</a>(int32 proxyId, <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabb1, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; displacement);
<a name="l00081"></a>00081 
<a name="l00084"></a>00084         <span class="keywordtype">void</span>* <a class="code" href="classb2_dynamic_tree.html#a44ab57dce3c42b0a5847a64e489a71ce">GetUserData</a>(int32 proxyId) <span class="keyword">const</span>;
<a name="l00085"></a>00085 
<a name="l00087"></a>00087         <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; <a class="code" href="classb2_dynamic_tree.html#adf4676b1c34a57b4451bcbeaebe65687" title="Get the fat AABB for a proxy.">GetFatAABB</a>(int32 proxyId) <span class="keyword">const</span>;
<a name="l00088"></a>00088 
<a name="l00091"></a>00091         <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00092"></a>00092         <span class="keywordtype">void</span> <a class="code" href="classb2_dynamic_tree.html#adf70aee89b4692fc79d65b1f54308585">Query</a>(T* callback, <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabb) <span class="keyword">const</span>;
<a name="l00093"></a>00093 
<a name="l00101"></a>00101         <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00102"></a>00102         <span class="keywordtype">void</span> <a class="code" href="classb2_dynamic_tree.html#abd7a5c6a5bc109dbbdb0ec3aae039648">RayCast</a>(T* callback, <span class="keyword">const</span> <a class="code" href="structb2_ray_cast_input.html" title="Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).">b2RayCastInput</a>&amp; input) <span class="keyword">const</span>;
<a name="l00103"></a>00103 
<a name="l00105"></a>00105         <span class="keywordtype">void</span> <a class="code" href="classb2_dynamic_tree.html#abfac96c615b08406cba3e53b39800f1c" title="Validate this tree. For testing.">Validate</a>() <span class="keyword">const</span>;
<a name="l00106"></a>00106 
<a name="l00109"></a>00109         int32 <a class="code" href="classb2_dynamic_tree.html#add7e09cdf279e7c0031da9dfd4cdf4db">GetHeight</a>() <span class="keyword">const</span>;
<a name="l00110"></a>00110 
<a name="l00113"></a>00113         int32 <a class="code" href="classb2_dynamic_tree.html#ae02c45d1a68b42e59d170438ddbb7977">GetMaxBalance</a>() <span class="keyword">const</span>;
<a name="l00114"></a>00114 
<a name="l00116"></a>00116         float32 <a class="code" href="classb2_dynamic_tree.html#ad78282a720c451e032b43c34cba02f1a" title="Get the ratio of the sum of the node areas to the root area.">GetAreaRatio</a>() <span class="keyword">const</span>;
<a name="l00117"></a>00117 
<a name="l00119"></a>00119         <span class="keywordtype">void</span> <a class="code" href="classb2_dynamic_tree.html#abd146017cfec1cf5ea7b87331f30a3ff" title="Build an optimal tree. Very expensive. For testing.">RebuildBottomUp</a>();
<a name="l00120"></a>00120 
<a name="l00121"></a>00121 <span class="keyword">private</span>:
<a name="l00122"></a>00122 
<a name="l00123"></a>00123         int32 AllocateNode();
<a name="l00124"></a>00124         <span class="keywordtype">void</span> FreeNode(int32 node);
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         <span class="keywordtype">void</span> InsertLeaf(int32 node);
<a name="l00127"></a>00127         <span class="keywordtype">void</span> RemoveLeaf(int32 node);
<a name="l00128"></a>00128 
<a name="l00129"></a>00129         int32 Balance(int32 index);
<a name="l00130"></a>00130 
<a name="l00131"></a>00131         int32 ComputeHeight() <span class="keyword">const</span>;
<a name="l00132"></a>00132         int32 ComputeHeight(int32 nodeId) <span class="keyword">const</span>;
<a name="l00133"></a>00133 
<a name="l00134"></a>00134         <span class="keywordtype">void</span> ValidateStructure(int32 index) <span class="keyword">const</span>;
<a name="l00135"></a>00135         <span class="keywordtype">void</span> ValidateMetrics(int32 index) <span class="keyword">const</span>;
<a name="l00136"></a>00136 
<a name="l00137"></a>00137         int32 m_root;
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         <a class="code" href="structb2_tree_node.html" title="A node in the dynamic tree. The client does not interact with this directly.">b2TreeNode</a>* m_nodes;
<a name="l00140"></a>00140         int32 m_nodeCount;
<a name="l00141"></a>00141         int32 m_nodeCapacity;
<a name="l00142"></a>00142 
<a name="l00143"></a>00143         int32 m_freeList;
<a name="l00144"></a>00144 
<a name="l00146"></a>00146         uint32 m_path;
<a name="l00147"></a>00147 
<a name="l00148"></a>00148         int32 m_insertionCount;
<a name="l00149"></a>00149 };
<a name="l00150"></a>00150 
<a name="l00151"></a><a class="code" href="classb2_dynamic_tree.html#a44ab57dce3c42b0a5847a64e489a71ce">00151</a> <span class="keyword">inline</span> <span class="keywordtype">void</span>* <a class="code" href="classb2_dynamic_tree.html#a44ab57dce3c42b0a5847a64e489a71ce">b2DynamicTree::GetUserData</a>(int32 proxyId)<span class="keyword"> const</span>
<a name="l00152"></a>00152 <span class="keyword"></span>{
<a name="l00153"></a>00153         b2Assert(0 &lt;= proxyId &amp;&amp; proxyId &lt; m_nodeCapacity);
<a name="l00154"></a>00154         <span class="keywordflow">return</span> m_nodes[proxyId].userData;
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 
<a name="l00157"></a><a class="code" href="classb2_dynamic_tree.html#adf4676b1c34a57b4451bcbeaebe65687">00157</a> <span class="keyword">inline</span> <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; <a class="code" href="classb2_dynamic_tree.html#adf4676b1c34a57b4451bcbeaebe65687" title="Get the fat AABB for a proxy.">b2DynamicTree::GetFatAABB</a>(int32 proxyId)<span class="keyword"> const</span>
<a name="l00158"></a>00158 <span class="keyword"></span>{
<a name="l00159"></a>00159         b2Assert(0 &lt;= proxyId &amp;&amp; proxyId &lt; m_nodeCapacity);
<a name="l00160"></a>00160         <span class="keywordflow">return</span> m_nodes[proxyId].<a class="code" href="structb2_tree_node.html#a798f1a594b33c713be45e76e79912239" title="Enlarged AABB.">aabb</a>;
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162 
<a name="l00163"></a>00163 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00164"></a><a class="code" href="classb2_dynamic_tree.html#adf70aee89b4692fc79d65b1f54308585">00164</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classb2_dynamic_tree.html#adf70aee89b4692fc79d65b1f54308585">b2DynamicTree::Query</a>(T* callback, <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabb)<span class="keyword"> const</span>
<a name="l00165"></a>00165 <span class="keyword"></span>{
<a name="l00166"></a>00166         <a class="code" href="classb2_growable_stack.html">b2GrowableStack&lt;int32, 256&gt;</a> stack;
<a name="l00167"></a>00167         stack.Push(m_root);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169         <span class="keywordflow">while</span> (stack.GetCount() &gt; 0)
<a name="l00170"></a>00170         {
<a name="l00171"></a>00171                 int32 nodeId = stack.Pop();
<a name="l00172"></a>00172                 <span class="keywordflow">if</span> (nodeId == b2_nullNode)
<a name="l00173"></a>00173                 {
<a name="l00174"></a>00174                         <span class="keywordflow">continue</span>;
<a name="l00175"></a>00175                 }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177                 <span class="keyword">const</span> <a class="code" href="structb2_tree_node.html" title="A node in the dynamic tree. The client does not interact with this directly.">b2TreeNode</a>* node = m_nodes + nodeId;
<a name="l00178"></a>00178 
<a name="l00179"></a>00179                 <span class="keywordflow">if</span> (b2TestOverlap(node-&gt;<a class="code" href="structb2_tree_node.html#a798f1a594b33c713be45e76e79912239" title="Enlarged AABB.">aabb</a>, aabb))
<a name="l00180"></a>00180                 {
<a name="l00181"></a>00181                         <span class="keywordflow">if</span> (node-&gt;IsLeaf())
<a name="l00182"></a>00182                         {
<a name="l00183"></a>00183                                 <span class="keywordtype">bool</span> proceed = callback-&gt;QueryCallback(nodeId);
<a name="l00184"></a>00184                                 <span class="keywordflow">if</span> (proceed == <span class="keyword">false</span>)
<a name="l00185"></a>00185                                 {
<a name="l00186"></a>00186                                         <span class="keywordflow">return</span>;
<a name="l00187"></a>00187                                 }
<a name="l00188"></a>00188                         }
<a name="l00189"></a>00189                         <span class="keywordflow">else</span>
<a name="l00190"></a>00190                         {
<a name="l00191"></a>00191                                 stack.Push(node-&gt;child1);
<a name="l00192"></a>00192                                 stack.Push(node-&gt;child2);
<a name="l00193"></a>00193                         }
<a name="l00194"></a>00194                 }
<a name="l00195"></a>00195         }
<a name="l00196"></a>00196 }
<a name="l00197"></a>00197 
<a name="l00198"></a>00198 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00199"></a><a class="code" href="classb2_dynamic_tree.html#abd7a5c6a5bc109dbbdb0ec3aae039648">00199</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classb2_dynamic_tree.html#abd7a5c6a5bc109dbbdb0ec3aae039648">b2DynamicTree::RayCast</a>(T* callback, <span class="keyword">const</span> <a class="code" href="structb2_ray_cast_input.html" title="Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).">b2RayCastInput</a>&amp; input)<span class="keyword"> const</span>
<a name="l00200"></a>00200 <span class="keyword"></span>{
<a name="l00201"></a>00201         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> p1 = input.p1;
<a name="l00202"></a>00202         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> p2 = input.p2;
<a name="l00203"></a>00203         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> r = p2 - p1;
<a name="l00204"></a>00204         b2Assert(r.<a class="code" href="structb2_vec2.html#af66641b887488490e2168bfafc5a7e36">LengthSquared</a>() &gt; 0.0f);
<a name="l00205"></a>00205         r.<a class="code" href="structb2_vec2.html#adda78c92f318fe53d8a53f9b5cfd8e41" title="Convert this vector into a unit vector. Returns the length.">Normalize</a>();
<a name="l00206"></a>00206 
<a name="l00207"></a>00207         <span class="comment">// v is perpendicular to the segment.</span>
<a name="l00208"></a>00208         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> v = b2Cross(1.0f, r);
<a name="l00209"></a>00209         <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> abs_v = b2Abs(v);
<a name="l00210"></a>00210 
<a name="l00211"></a>00211         <span class="comment">// Separating axis for segment (Gino, p80).</span>
<a name="l00212"></a>00212         <span class="comment">// |dot(v, p1 - c)| &gt; dot(|v|, h)</span>
<a name="l00213"></a>00213 
<a name="l00214"></a>00214         float32 maxFraction = input.maxFraction;
<a name="l00215"></a>00215 
<a name="l00216"></a>00216         <span class="comment">// Build a bounding box for the segment.</span>
<a name="l00217"></a>00217         <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a> segmentAABB;
<a name="l00218"></a>00218         {
<a name="l00219"></a>00219                 <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> t = p1 + maxFraction * (p2 - p1);
<a name="l00220"></a>00220                 segmentAABB.<a class="code" href="structb2_a_a_b_b.html#ab94b68fbad8348b22b0522469b11bdb5" title="the lower vertex">lowerBound</a> = b2Min(p1, t);
<a name="l00221"></a>00221                 segmentAABB.<a class="code" href="structb2_a_a_b_b.html#ad4a8ec483ba13a2c02918b01d058a18f" title="the upper vertex">upperBound</a> = b2Max(p1, t);
<a name="l00222"></a>00222         }
<a name="l00223"></a>00223 
<a name="l00224"></a>00224         <a class="code" href="classb2_growable_stack.html">b2GrowableStack&lt;int32, 256&gt;</a> stack;
<a name="l00225"></a>00225         stack.Push(m_root);
<a name="l00226"></a>00226 
<a name="l00227"></a>00227         <span class="keywordflow">while</span> (stack.GetCount() &gt; 0)
<a name="l00228"></a>00228         {
<a name="l00229"></a>00229                 int32 nodeId = stack.Pop();
<a name="l00230"></a>00230                 <span class="keywordflow">if</span> (nodeId == b2_nullNode)
<a name="l00231"></a>00231                 {
<a name="l00232"></a>00232                         <span class="keywordflow">continue</span>;
<a name="l00233"></a>00233                 }
<a name="l00234"></a>00234 
<a name="l00235"></a>00235                 <span class="keyword">const</span> <a class="code" href="structb2_tree_node.html" title="A node in the dynamic tree. The client does not interact with this directly.">b2TreeNode</a>* node = m_nodes + nodeId;
<a name="l00236"></a>00236 
<a name="l00237"></a>00237                 <span class="keywordflow">if</span> (b2TestOverlap(node-&gt;<a class="code" href="structb2_tree_node.html#a798f1a594b33c713be45e76e79912239" title="Enlarged AABB.">aabb</a>, segmentAABB) == <span class="keyword">false</span>)
<a name="l00238"></a>00238                 {
<a name="l00239"></a>00239                         <span class="keywordflow">continue</span>;
<a name="l00240"></a>00240                 }
<a name="l00241"></a>00241 
<a name="l00242"></a>00242                 <span class="comment">// Separating axis for segment (Gino, p80).</span>
<a name="l00243"></a>00243                 <span class="comment">// |dot(v, p1 - c)| &gt; dot(|v|, h)</span>
<a name="l00244"></a>00244                 <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> c = node-&gt;<a class="code" href="structb2_tree_node.html#a798f1a594b33c713be45e76e79912239" title="Enlarged AABB.">aabb</a>.<a class="code" href="structb2_a_a_b_b.html#aa26703e234bd6fb30fd443cd5001795a" title="Get the center of the AABB.">GetCenter</a>();
<a name="l00245"></a>00245                 <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> h = node-&gt;<a class="code" href="structb2_tree_node.html#a798f1a594b33c713be45e76e79912239" title="Enlarged AABB.">aabb</a>.<a class="code" href="structb2_a_a_b_b.html#aff8b9aa64069a33fe45025299aa0e9b7" title="Get the extents of the AABB (half-widths).">GetExtents</a>();
<a name="l00246"></a>00246                 float32 separation = b2Abs(b2Dot(v, p1 - c)) - b2Dot(abs_v, h);
<a name="l00247"></a>00247                 <span class="keywordflow">if</span> (separation &gt; 0.0f)
<a name="l00248"></a>00248                 {
<a name="l00249"></a>00249                         <span class="keywordflow">continue</span>;
<a name="l00250"></a>00250                 }
<a name="l00251"></a>00251 
<a name="l00252"></a>00252                 <span class="keywordflow">if</span> (node-&gt;IsLeaf())
<a name="l00253"></a>00253                 {
<a name="l00254"></a>00254                         <a class="code" href="structb2_ray_cast_input.html" title="Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).">b2RayCastInput</a> subInput;
<a name="l00255"></a>00255                         subInput.p1 = input.p1;
<a name="l00256"></a>00256                         subInput.p2 = input.p2;
<a name="l00257"></a>00257                         subInput.maxFraction = maxFraction;
<a name="l00258"></a>00258 
<a name="l00259"></a>00259                         float32 value = callback-&gt;RayCastCallback(subInput, nodeId);
<a name="l00260"></a>00260 
<a name="l00261"></a>00261                         <span class="keywordflow">if</span> (value == 0.0f)
<a name="l00262"></a>00262                         {
<a name="l00263"></a>00263                                 <span class="comment">// The client has terminated the ray cast.</span>
<a name="l00264"></a>00264                                 <span class="keywordflow">return</span>;
<a name="l00265"></a>00265                         }
<a name="l00266"></a>00266 
<a name="l00267"></a>00267                         <span class="keywordflow">if</span> (value &gt; 0.0f)
<a name="l00268"></a>00268                         {
<a name="l00269"></a>00269                                 <span class="comment">// Update segment bounding box.</span>
<a name="l00270"></a>00270                                 maxFraction = value;
<a name="l00271"></a>00271                                 <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a> t = p1 + maxFraction * (p2 - p1);
<a name="l00272"></a>00272                                 segmentAABB.<a class="code" href="structb2_a_a_b_b.html#ab94b68fbad8348b22b0522469b11bdb5" title="the lower vertex">lowerBound</a> = b2Min(p1, t);
<a name="l00273"></a>00273                                 segmentAABB.<a class="code" href="structb2_a_a_b_b.html#ad4a8ec483ba13a2c02918b01d058a18f" title="the upper vertex">upperBound</a> = b2Max(p1, t);
<a name="l00274"></a>00274                         }
<a name="l00275"></a>00275                 }
<a name="l00276"></a>00276                 <span class="keywordflow">else</span>
<a name="l00277"></a>00277                 {
<a name="l00278"></a>00278                         stack.Push(node-&gt;child1);
<a name="l00279"></a>00279                         stack.Push(node-&gt;child2);
<a name="l00280"></a>00280                 }
<a name="l00281"></a>00281         }
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283 
<a name="l00284"></a>00284 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Sat Sep 17 2011 17:35:55 for Box2D by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
